/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Helios Tower Elevator that travels between the 2nd to 99th floors.
 * @author Golden Kevin
 */
function enter(pi) {
	var em = pi.getPlayer().getClient().getChannelServer().getEventSM().getEventManager("Elevator");
	if (em != null) {
		var state = em.getProperty("state")
		var toggleMsg = em.getProperty("toggleMsg").equals("true");
		if (pi.getPlayer().getMapId() == 222020200) {
			if (state.equals("isUp")) {
				pi.warp(222020210, "out00");
				return true;
			} else if (toggleMsg) {
				if (state.equals("isDown")) {
					pi.getPlayer().dropMessage(0, "The elevator is currently on the bottom floor. Please wait a bit longer.");
				} else if (state.equals("goingUp")) {
					pi.getPlayer().dropMessage(0, "The elevator is currently coming up. It'll arrive shortly.");
				} else if (state.equals("goingDown")) {
					pi.getPlayer().dropMessage(0, "The elevator is currently going down. Please wait a few minutes.");
				} else {
					pi.getPlayer().dropMessage(5, "Invalid Elevator state. Something went wrong...");
				}
			}
		} else if (pi.getPlayer().getMapId() == 222020100) {
			if (state.equals("isDown")) {
				pi.warp(222020110, "out00");
				return true;
			} else if (toggleMsg) {
				if (state.equals("isUp")) {
					pi.getPlayer().dropMessage(0, "The elevator is currently on the top floor. Please wait a bit longer.");
				} else if (state.equals("goingDown")) {
					pi.getPlayer().dropMessage(0, "The elevator is currently coming down. It'll arrive shortly.");
				} else if (state.equals("goingUp")) {
					pi.getPlayer().dropMessage(0, "The elevator is currently going up. Please wait a few minutes.");
				} else {
					pi.getPlayer().dropMessage(5, "Invalid Elevator state. Something went wrong...");
				}
			}
		} else {
			pi.getPlayer().dropMessage(5, "Invalid Elevator Map ID. Something went wrong...");
		}
	} else {
		if (pi.getPlayer().getMapId() == 222020200) {
			pi.warp(222020100, "in00");
			return true;
		} else if (pi.getPlayer().getMapId() == 222020100) {
			pi.warp(222020200, "in00");
			return true;
		} else {
			pi.getPlayer().dropMessage(5, "Invalid Elevator Map ID. Something went wrong...");
		}
	}
	return false;
}